package com.huawei.struts.action;

import java.io.File;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class Test {
	 public static void main(String[] args) {    
		 
		 try { 
			 Workbook book= Workbook.getWorkbook(new File("c:/Test.xls")); 
			 //获得第一个工作表对象 
			 Sheet sheet=book.getSheet(0); 
			 //得到第一列第一行的单元格 
			 
			 int rows=sheet.getRows();
			 int cols=sheet.getColumns();
			 
			 for(int i=1;i<rows;i++)
			 {
				 System.out.println("id="+sheet.getCell(0,i).getContents()+"  name="+sheet.getCell(1,i).getContents()+"  pwd="+sheet.getCell(2,i).getContents()); 
			}
			 Cell id=sheet.getCell(0,1); 
			 Cell name=sheet.getCell(0,2);
			 Cell pwd=sheet.getCell(0,3);
			 //String result=cell1.getContents(); 
			 //System.out.println(rows+" "+clos);
			 
			 book.close(); 
			 }catch(Exception e) { 
			 System.out.println(e); 
			 } 

	       /* try {       
	             WritableWorkbook book = Workbook.createWorkbook(new File("Test11.xls"));         
	             WritableSheet sheet = book.createSheet("Sheet_1", 0);    
	             
	             WritableFont wf = new WritableFont(WritableFont.ARIAL, 15,
	            	     WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
	            	     jxl.format.Colour.CORAL); // 定义格式 字体 下划线 斜体 粗体 颜色
	            	   WritableCellFormat wcf = new WritableCellFormat(wf); // 单元格定义
	            	   
	            	   wcf.setBackground(jxl.format.Colour.BLUE); // 设置单元格的背景颜色
	            	   wcf.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
	            	   String[] title={"id","name","password"};
	            	   for(int i=0;i<title.length;i++)
	            	   {
	            		   sheet.addCell(new Label(i, 0, "id",wcf));
	            		    
	            	   }
	            	   
	            	   for(int i=0;i<title.length;i++)
	            	   {
	            		   sheet.addCell(new Label(i, 0, "id",wcf));
	            		   for(int j=1;j<12;j++)
	            		   {
	            			   sheet.addCell(new jxl.write.Number(i, j, 12));    
	            		   }
	            	   }
	             book.write();       
	             book.close();    
	         } catch (Exception e) {    
	             e.printStackTrace();    
	         }    */
	     }    

}
